package newx
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	/**
	 * 对象基类
	 * 主要功能：
	 * 1、动态属性管理
	 * 2、事件派发能力
	 * 
	 * @author riki(王俊)	2009/4/17
	 * 	 
	 * 
	 */	
	public class BaseObject extends EventDispatcher
	{
		/**参数容器*/
		public	var Properties		:Object;
		
		public function BaseObject(target:IEventDispatcher=null)
		{
			super(target);
			Properties	=	new Object();
		}
		
		/**取得属性*/
		public final function GetProperties(PropertiesName : String):*
		{
			if (CheckProperties(PropertiesName))
			{
				return this.Properties[PropertiesName];
			}
			else
			{
//				throw new Error("[BaseControl::GetProperties]指定参数不存在！" + PropertiesName);
				return null;
			}
		}

		/**设置属性*/		
		public final function HandleProperties(PropertiesName:String, PropertiesValue:*):void
		{
			this.Properties[PropertiesName] = PropertiesValue;
		}
		
		/**删除属性*/
		public final function DeleteProperties(PropertiesName : String):void
		{
			if (this.Properties.hasOwnProperty(PropertiesName) == true)
			{
				delete this.Properties[PropertiesName];
			}
			else
			{
				//throw new Error("[BaseObject::DeleteProperties]指定参数不存在！");
			}
		}
		
		public final function clearProperties():void
		{
			Properties	=	new Object();
		}
		
		/**检测属性是否存在*/
		public final function CheckProperties(PropertiesName : String):Boolean
		{
			return this.Properties.hasOwnProperty(PropertiesName)
		}
		
		public function getDataForEach(func:Function):void
		{
			for(var p:String in this.Properties)
			{
				func.call(this,p,GetProperties(p));
			}
		}
		
		static public function fromObj(obj:Object):BaseObject
		{
			var baseObj:BaseObject	=	new BaseObject();
			for(var proName:String	in 	obj)
			{
				baseObj.HandleProperties(proName,obj[proName]);
			}
			return baseObj;
		}
	}
}